//author:kakake
class tsschedualDao {
    public data = {
        dbConn: TSLobsterAPI.Program.GetDbConn(),
        WorkId: 1
    }

    constructor(workid: number) {
        this.data.WorkId = workid;
    }

    /**
     * 获取科室
     */
    getselectdept() {
        let strsql = 'select DeptId,Name from wpmt_basedept where delflag=0 and workid=@workid';
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, { workid: this.data.WorkId });
    }

    /**
    * 获取医生列表
    */
    gettabledoctor(deptId, status, keyword, pageInfo) {
        let strsql = 'select * from wpmt_doctor where workid=@workid and empname like @keyword ';

        if (deptId > 0) {
            strsql += ' and deptid=@deptid';
        }
        //已出诊
        if (status == 1) {
            strsql += ' and (select COUNT(*) from wpmt_docschedual where workid=wpmt_doctor.workid and  doctid=wpmt_doctor.empid and schedualdate>GETDATE())>0';
        }//未出诊
        else if (status == 2) {
            strsql += ' and (select COUNT(*) from wpmt_docschedual where workid=wpmt_doctor.workid and  doctid=wpmt_doctor.empid and schedualdate>GETDATE())=0';
        }

        let dbparam = {
            workid: this.data.WorkId,
            deptid: deptId,
            keyword: '%' + keyword + '%'
        }

        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparam, pageInfo);

    }

    /**
     * 获取
     */
    gettableschedual(SchedType, doctId, sdate, edate, pageInfo) {
        let strsql = 'select * from WPMT_DocSchedual where workid=@workid and SchedType=@SchedType and DoctID=@doctId and SchedualDate >= @sdate and SchedualDate <=@edate';
        let dbparam = {
            workid: this.data.WorkId,
            doctId: doctId,
            sdate: sdate,
            edate: edate,
            SchedType: SchedType
        }

        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparam, pageInfo);
    }

    /**
     * 停用、启用
     */
    stopschedual(schedId, flag) {
        let strsql = 'update WPMT_DocSchedual set Flag=@flag where SchedualID=@schedId';
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { schedId: schedId, flag: flag });
    }

    setdoctorprice(Id, RegPrice, IHPrice) {
        let strsql = 'update WPMT_Doctor set RegPrice=@RegPrice,IHPrice=@IHPrice where Id=@Id';
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { Id: Id, RegPrice: RegPrice, IHPrice: IHPrice });
    }

}